import {get,post,put} from '@/http/http'
import md5 from 'js-md5';  
 
// 登录接口
function getUserLogin(person){
  let str = person.password;
  return post('/user/login/loginByPasword',{
      captchaCode: person.captchaCode,
      code: "",
      email: "",
      password: str,
      phone: person.phone,
      username: ""
  })
}
// 图片验证码接口
function getImgCode(){
  return get('/user/login/capthca')
}
// 获取邮箱验证码
function getEmailCode(email){
  return get('/user/login/send/' + email)
}
// 邮箱登录
function getEmailLogin(person){
  return post('/user/login/loginFromEmailCode',{
    captchaCode: "",
    code: person.code,
    email: person.email,
    password: "",
    phone: "",
    username: ""
  })
}
// 注册
function getRegister(person) {
  return post('/user/register/user',{
    code: person.code,
    email: person.email,
    password: person.password,
    phone: person.phone,
    username: person.username
  })
}
// 获取注册验证码
function getRegCode(email) {
  return post('/user/register/email/' + email)
}
// 请求用户接口
function getUser(){
  return get('/user/user/OwnMes')
}
// 退出登录
function getLoginOut(){
  return get('/user/login/loginOut')
}
// 修改头像
function replaceAvatar(file) {
  return post('/user/user/avatar',{
  headers: {
    //请求头这个一定要写
        'Content-Type': 'multipart/form-data',
    },
    file:file
  })
}
// 修改密码
function updatePwd(oldpwd,newpwd) {
  return put('/user/user/updatePwd?oldpassword='+oldpwd+'&newpassword='+newpwd)
}

// 修改用户信息
function updateUser(editUserForm){
  return post('/user/user/updateOwnMes',{
    email: editUserForm.email,
    nickname: editUserForm.nickname,
    phone: editUserForm.phone,
    realName: editUserForm.realname,
    sex: editUserForm.sex,
    signature: editUserForm.signature
  })
}


export default {
  getUserLogin,
  getImgCode,
  getEmailCode,
  getEmailLogin,
  getRegister,
  getRegCode,
  getUser,
  getLoginOut,
  replaceAvatar,
  updatePwd,
  updateUser,
}